<?php 
    include_once('../public/index.php');
    $config = include_once('../../public/config/config.php');
    include_once('../../public/func/db.php');
    $table = 'reply';
    if(isset($_GET['keywords']) && !empty($_GET['keywords'])){
        if(is_numeric($_GET['keywords'])){
            $key = 'r.id';
        }else{
            $key = 'a.title';
        }
        $where ='where '.$key.' like "%'.$_GET['keywords'].'%"';
        $sort = $_GET['keywords'];
    }else{
        $where = '';
        $sort = '';
    }
    $page = dispage($config,$table,'as r left join article as a on r.aid=a.id 
                   left join user as u on r.uid=u.id '.$where,
                   'r.id as id,a.title as aid,u.nicname as uid,r.reply,r.ctime');
    $res = $page[4];
?>
<div class="main-wrap">
    <div class="crumb-wrap">
        <div class="crumb-list"><i class="icon-font"></i><a href="/admin/index.php">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">评论管理</span></div>
        </div>
        <div class="search-wrap">
            <div class="search-content">
                <form action="/admin/reply/reply.php" method="get">
                    <table class="search-tab">
                        <tr>  
                            <th width="70">关键字:</th>
                            <td><input class="common-text" placeholder="关键字" name="keywords" value="" id="" type="text"></td>
                            <td><input class="btn btn-primary btn2" value="查询" type="submit"></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
                <div class="result-title">
                    <div class="result-list">
                        <a id="batchDel" href="javascript:void(0)"><i class="icon-font"></i>批量删除</a>
                        <a id="updateOrd" href="javascript:void(0)"><i class="icon-font"></i>更新排序</a>
                    </div>
                </div>
                <div class="result-content">
                    <table class="result-tab" width="100%">
                        <tr>
                            <th class="tc" width="5%"><input class="allChoose" name="" type="checkbox"></th>
                            <th>ID</th>
                            <th>博文标题</th>
                            <th>用户</th>
                            <th>评论</th>
                            <th>更新时间</th>
                            <th>操作</th>
                        </tr>
                        <?php
                            foreach ($res as $k => $v) {
                                echo '<tr>';
                                echo '<th class="tc" width="5%"><input class="allChoose" name="" 
                                     type="checkbox"></th>';
                                echo '<td>'.$v['id'].'</td>';
                                echo '<td>'.$v['aid'].'</td>';
                                echo '<td>'.$v['uid'].'</td>';
                                echo '<td>'.$v['reply'].'</td>';
                                echo '<td>'.date('Y-m-d H:i:s',$v['ctime']).'</td>';
                                echo '<td><a class="link-update" href="updatereply.php?id='.$v['id'].'">
                                      修改</a>
                                      <a class="link-del" href="deletereply.php?id='.$v['id'].'">
                                      删除</a></td>';
                                echo '</tr>';
                            }
                        ?>
                    </table>
                </div>
            </form>
            </form>
            <br>
            <a href="<?php echo $_SERVER['PHP_SELF'] ?>?keywords=<?php echo $sort?>&p=1">首页</a>
            <a href="<?php echo $_SERVER['PHP_SELF'] ?>?keywords=<?php echo $sort?>&p=<?php echo $page[0]?>">上一页</a>
            <?php
                $leftRight = 1;
                $left = $page[3] - $leftRight;
                $right = $page[3] + $leftRight;
                if($left < 1){
                    $left = 1;
                    $right = $left + 2*$leftRight;
                }
                if($right > $page[2]){
                    $right = $page[2];
                    if($right > 2*$leftRight){
                        $left = $right - 2*$leftRight;
                    }else{
                        $left = 1;
                    }
                }

                if($left > 1){
                    echo '...';
                }

                for($i = $left;$i <= $right;$i++){
                    $color = ($i == $page[3])?'style = "color:red;font-weight:900"':'';
                    echo '<a '.$color.' href="'.$_SERVER['PHP_SELF'].'?keywords='.$sort.'&p='.$i.'">'.$i.'</a>&nbsp;';
                }

                if($right < $page[2]){
                    echo '...';
                }
            ?>
            <a href="<?php echo $_SERVER['PHP_SELF'] ?>?keywords=<?php echo $sort?>&p=<?php echo $page[1]?>">下一页</a>
            <a href="<?php echo $_SERVER['PHP_SELF'] ?>?keywords=<?php echo $sort?>&p=<?php echo $page[2]?>">尾页</a>
            <span>总共<?php echo $page[2]?>页，当前：<?php echo $page[3]?>/<?php echo $page[2]?></span>
            <hr>
            <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="get">
                <input type="hidden" name="keywords" value="<?php echo $sort?>">
                跳转至：<input type="text" name="p">
                <input type="submit" value="go">
            </form>
        </div>
    </div>
</div>